﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SoundPlayer : MonoBehaviour {
	/**
	灵光一闪的经典之作
	 */
	public static string VoliceName = null;
	private static SoundPlayer sound;
	public static float soundNum;
	public string onplay = ""; 

	void Awake()
	{
		DontDestroyOnLoad (gameObject);
	}
	// Use this for initialization
	void Start () {
		gameObject.name = "Roaring";
		VoliceName = gameObject.name;
		sound = this;
	}

	private Dictionary<string,AudioClip> dic = new Dictionary<string,AudioClip> ();
	public AudioSource Sound;
	public void be(string str)
	{
		onplay = str;

		/*
		if ( !InstallNotice.Sound ) {
			return;
		}
		*/
		if (dic.ContainsKey(str)) {
			Sound.clip = dic [str];
			Sound.Play();
		} else {
			Sound.clip = (AudioClip)Resources.Load("Sound/"+str, typeof(AudioClip));//调用Resources方法加载AudioClip资源
			Sound.Play();
			dic[str] = Sound.clip;
		}
	}

	public void stop(){
		Sound.Stop ();
	}

	public static void replay(){
		if( sound.onplay != "" ){
			sound.be(sound.onplay);
		}
	}

	public static void Stop(){
		sound.stop ();
	}

	public static void play(string str){
		Debug.Log ("sound.be:" + str);
		sound.be (str);
	}
	
	// Update is called once per frame
	void Update () {
		Sound.volume = SetUpView.SoundValue;
		soundNum = Sound.volume;
	}
}
